package com.biscuit.page.basicservice.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.biscuit.page.basicservice.model.entities.mysql.BaseEntity;
import com.biscuit.page.basicservice.model.enums.BaseEntityEnum;

import java.time.LocalDateTime;

/**
 * @author biscuit
 * @createTime 2024/5/18 10:22
 */
public class WrapperUtil {

    public static <T extends BaseEntity> LambdaQueryWrapper<T> instanceQuery(Class<T> clazz) {
        return Wrappers.lambdaQuery(clazz).eq(BaseEntity::getIsDeleted, BaseEntityEnum.NOT_DELETED.getValue());
    }

    public static <T extends BaseEntity> LambdaUpdateWrapper<T> instanceUpdate(Class<T> clazz) {
        return Wrappers.lambdaUpdate(clazz).eq(BaseEntity::getIsDeleted, BaseEntityEnum.NOT_DELETED.getValue())
                .set(BaseEntity::getLastUpdateTime, LocalDateTime.now());
    }

    public static  <T extends BaseEntity> LambdaUpdateWrapper<T> instanceDelete(Class<T> clazz) {
        return Wrappers.lambdaUpdate(clazz)
                .set(BaseEntity::getDeleteTime, LocalDateTime.now())
                .set(BaseEntity::getLastUpdateTime, LocalDateTime.now())
                .set(BaseEntity::getIsDeleted, BaseEntityEnum.YES_DELETED.getValue());
    }

}
